package com.jh.fcsm.controller.sys;

import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.github.pagehelper.PageInfo;

import com.jh.fcsm.beans.sys.SysTableSet;
import com.jh.fcsm.beans.sys.vo.SysTableSetVo;
import com.jh.fcsm.common.RestApiResponse;
import com.jh.fcsm.common.annotation.RepeatSubAnnotation;
import com.jh.fcsm.common.annotation.SystemLogAnnotation;
import com.jh.fcsm.common.BaseController;
import com.jh.fcsm.service.sys.SysTableSetService;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

/**
 * 用户格设置Controller
 * 
 * @author linq
 * @date 2024-01-31
 */
@RestController
@RequestMapping("/sys/tableset")
@Api(value="用户格设置", description="用户格设置")
public class SysTableSetController extends BaseController{
    @Autowired
    private SysTableSetService sysTableSetService;
	/**
	 * 新增用户格设置
	 *@param sysTableSet 用户格设置数据 json
	 *@return RestApiResponse<?>
	 *@author linq
	 */
	@RepeatSubAnnotation
	@PostMapping("/save")
	@ApiOperation(value = "新增用户格设置", notes = "新增用户格设置")
	@SystemLogAnnotation(type = "用户格设置",value = "新增用户格设置")
	public RestApiResponse<?> saveSysTableSet(@RequestBody SysTableSetVo sysTableSet) {
		String id = sysTableSetService.saveListTableset(sysTableSet);
		return RestApiResponse.ok(id);
	}
	/**
	 * 新增列显示字段
	 *
	 * @param sysTableSetVo 导出字段数据 json
	 * @return RestApiResponse<?>
	 * @author pw
	 */
	@RepeatSubAnnotation
	@PostMapping("/saveListTableset")
	@ApiOperation(value = "新增列显示字段", notes = "新增列显示字段")
	@SystemLogAnnotation(type = "列显示字段", value = "新增列显示字段")
	//@PreAuthorize("hasAuthority('" + PER_PREFIX + "save')")
	public RestApiResponse<?> saveListTableset(@RequestBody SysTableSetVo sysTableSetVo) {
		String id = sysTableSetService.saveListTableset(sysTableSetVo);
		return RestApiResponse.ok(id);
	}


	/**
	 * 查询列显示字段详情
	 *
	 * @return RestApiResponse<?>
	 * @author linq
	 */
	@GetMapping("/findByCurrentUser")
	@ApiOperation(value = "查询列显示字段详情", notes = "查询列显示字段详情")
	//@PreAuthorize("hasAuthority('"+PER_PREFIX+"find')")
	public RestApiResponse<?> findByCurrentUser(@RequestParam("key") String key) {
		SysTableSet sysTableSet = sysTableSetService.findByKeyAndUserId(key, getCurrentUserId());
		return RestApiResponse.ok(sysTableSet);
	}

	/**
	 * 查询列导出字段详情
	 *
	 * @return RestApiResponse<?>
	 * @author pw
	 */
	@GetMapping("/findByCurrentUserForExport")
	@ApiOperation(value = "查询列导出字段详情", notes = "查询列导出字段详情")
	//@PreAuthorize("hasAuthority('"+PER_PREFIX+"find')")
	public RestApiResponse<?> findByCurrentUserForExport(@RequestParam("key") String key) {
		SysTableSet sysTableSet = sysTableSetService.findByCurrentUserForExport(key, getCurrentUserId());
		return RestApiResponse.ok(sysTableSet);
	}

	/**
	 * 查询列显示字段详情
	 *
	 * @return RestApiResponse<?>
	 * @author linq
	 */
	@GetMapping("/findListHabitByCurrentUser")
	@ApiOperation(value = "查询列显示字段详情", notes = "查询列显示字段详情")
	//@PreAuthorize("hasAuthority('"+PER_PREFIX+"find')")
	public RestApiResponse<?> findListHabitByCurrentUser(@RequestParam("key") String key) {
		SysTableSet sysTableSet = sysTableSetService.findByKeyAndUserId(key, getCurrentUserId());
		return RestApiResponse.ok(sysTableSet);
	}

}
